<?php
function view_news_list($news_list)
{
	$list = "<table class='news_list'>\n";
	foreach ($news_list as $news)
	{
		$list = $list . view_news($news["title"], $news["publish_time"], $news["detail_view_url"]);
	}
	$list = $list . "</table>\n";

	return $list;
}

function view_news($title, $publish_time, $detail_view_url)
{
	$news = sprintf(
	"<table class='news_intro'>
		<tr> <td class='news_title'><a href='%s'>%s</a> </td></tr>
		<tr> <td class='news_publish_time'>%s</td> </tr>
		<tr> <td class='news_edit'><a href='%s'>获得详情</a></td> </tr>
	</table>",
	$detail_view_url,
	$title,
	$publish_time,
	$detail_view_url
	);
	return $news;
}

function view_news_list_index_page($news_list)
{
	$list = "<table class='news_list'>\n";
	foreach ($news_list as $news)
	{
		$list = $list . view_news_index_page($news["title"], $news["publish_time"], $news["detail_view_url"]);
	}
	$list = $list . "</table>\n";

	return $list;
}

function view_news_index_page($title, $publish_time, $detail_view_url)
{
	$news = sprintf(
	"<table class='news_intro'>
		<tr> <td class='news_title'><a href='%s'>%s</a> </td></tr>
	</table>",
	"/news/list.php",
	$title
	);
	return $news;
}

function view_news_page_list($page, $page_count, $type)
{
	$page_list = "";
	// 如果需要，显示上一页
	if ($page > 1)
	{
		if ($type)
		{
			$page_list = $page_list. sprintf("<a href=\"news_list.php?page=%d&type=%d\">上一页</a>", $page - 1, $type);
		}
		else
		{
			$page_list = $page_list. sprintf("<a href=\"news_list.php?page=%d\">上一页</a>", $page - 1);
		}
	}
	// 如果需要，显示下一页
	if ($page + 1 < $page_count)
	{
		if ($type)
		{
			$page_list = $page_list. sprintf("<a href=\"news_list.php?page=%d&type=%d\">下一页</a>", $page + 1, $type);
		}
		else
		{
			$page_list = $page_list. sprintf("<a href=\"news_list.php?page=%d\">下一页</a>", $page + 1);
		}
	}

	$page_list = $page_list. sprintf("%d/%d", $page, $page_count);
	return $page_list;
}

function view_news_detail($title, $content, $publish_time, $click_count)
{
	$detail = sprintf(
		"<!--news start-->
		<div class='news'>
		 <div class='news_title'>%s</div>
		 <div class='news_content'>%s</div>
		 <div class='news_publish_time'>%s</div>
		 <div class='news_click_count'>%d</div>
		 <div class='news_print'>打印此页</div>
		</div>
		<!--news end-->",
		$title,
		$content,
		$publish_time,
		$click_count
	);
	return $detail;
}
?>
